package net.xin.dao.impl;


import java.io.FileWriter;
import java.io.IOException;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Component;

import net.xin.dao.UserDAO;
import net.xin.model.User;

@Component(value="fileDAO")	/*相当于在xml中初始化对象*/
@Scope(value="singleton")
public class UserDAOFileImpl implements UserDAO {
	HibernateTemplate hibernateTemplate;
	
	@Resource	//装配
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	@Override
	public void save(User user) {

		try {
			FileWriter fw=new FileWriter("E:\\users.txt", true);
			fw.write(user.getUserName()+":"+user.getUserPwd());
			fw.write("\r\n");
			fw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	@Override
	public boolean isExists(User user) {
		// TODO Auto-generated method stub
		return hibernateTemplate.findByExample(user).size()>0;
	}

	@Override
	public User get(User user) {
		// TODO Auto-generated method stub
		return null;
	}

}
